<?php
abstract class MessageBase extends Object
{
    protected static $message = array();

    public static function Confirm($msg)
    {
        self::SetMessage($msg, 'confirm');
    }

    public static function Warning($msg)
    {
        self::SetMessage($msg, 'warning');
    }

    public static function Inform($msg)
    {
        self::SetMessage($msg, 'inform');
    }

    public static function Exception($ex)
    {
        Log::LogException($ex);
        self::Warning($ex->getMessage());
    }

    public static function SetMessage($msg, $type)
    {
        self::$message[$type][] = $msg;
        Session::Set('MessageFlash', self::$message);
    }

    public static function GetMessage($type)
    {
        $msg = empty(self::$message) && Session::IsExisted('MessageFlash') ? Session::Get('MessageFlash') : self::$message;
        return isset($msg[$type]) ? $msg[$type] : null;
    }

    public static function GetConfirmMsg()
    {
        return self::GetMessage('confirm');
    }

    public static function GetWarningMsg()
    {
        return self::GetMessage('warning');
    }

    public static function GetInfoMsg()
    {
        return self::GetMessage('info');
    }

    public static function ClearMessage()
    {
        self::$message = array();
        Session::Remove('MessageFlash');
    }
}
?>